<?php namespace Cms\Controller; 

use Hdphp\Controller\Controller;

class ModelController extends Controller{
    
    //GET /photo 索引
    public function index()
    {
        $model = Api('Model/getAll');
        View::with('model',$model)->make();
    }

    //GET /photo/create 创建界面
    public function create()
    {
        View::make();
    }

    //POST /photo 保存新增数据
    public function store()
    {
       if (Api('Model/store')) {
          $json = array(
            'code'    => 0,
            'message' => '创建成功'
            );
        }
        else {
          $json = array(
            'code'    => 1,
            'message' => Api('Model/getError')
            );
        }
        $this->ajax($json);
    }

    //GET /photo/{photo} 显示文章
    public function show()
    {
        
    }

    //GET /photo/{photo}/edit 更新界面
    public function edit($mid)
    {
        $field = Db::table('model')->where('mid',$mid)->first();
        View::with('field',$field)->make();
    }

    //PUT /photo/{photo} 更新数据
    public function update($id)
    {
        if (Api('Model/update')) {
          $json = array(
            'code'    => 0,
            'message' => '更新成功'
            );
        }
        else {
          $json = array(
            'code'    => 1,
            'message' => Api('Model/getError')
            );
        }
        $this->ajax($json);
    }

    //DELETE /photo/{photo} 删除
    public function destroy($id)
    {
        if (Api('Model/destroy',array($id))) {
          $json = array(
            'code'    => 0,
            'message' => '删除成功'
            );
        }
        else {
          $json = array(
            'code'    => 1,
            'message' => Api('Model/getError')
            );
        }
        $this->ajax($json);
    }
}